package cn.xd.base.persistence.mps.impl;


import cn.hutool.core.util.StrUtil;
import cn.xd.base.persistence.dos.AppUserThirdPartyDO;
import cn.xd.base.persistence.mapper.AppUserThirdPartyMapper;
import cn.xd.base.persistence.mps.AppUserThirdPartyMpService;
import cn.xd.core.response.CollectResult;
import cn.xd.core.response.ObjectResult;
import cn.xd.core.service.impl.BasicMpServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 移动端用户与第三方应用关联表 服务实现类
 * </p>
 *
 * @author chenyh
 * @since 2023-09-08
 */
@Service
public class AppUserThirdPartyMpServiceImpl extends BasicMpServiceImpl<AppUserThirdPartyMapper, AppUserThirdPartyDO> implements AppUserThirdPartyMpService {

    @Override
    public CollectResult<AppUserThirdPartyDO> listByUserId(Long userId) {
        return CollectResult.of(this.lambdaQuery().eq(AppUserThirdPartyDO::getUserId, userId).list());
    }

    @Override
    public ObjectResult<AppUserThirdPartyDO> getAppUserThirdPartyDO(String openId, String unionId, Integer type, Integer appUserType) {
        return getOneForLimitOneResult(Wrappers.lambdaQuery(AppUserThirdPartyDO.class).eq(AppUserThirdPartyDO::getAppUserType, appUserType)
                .eq(AppUserThirdPartyDO::getType, type).eq(AppUserThirdPartyDO::getOpenId, openId)
                .eq(StrUtil.isNotBlank(unionId), AppUserThirdPartyDO::getUnionId, unionId));
    }

}
